<template>
  <div>
    <ul>
      <li>
        {{arr}}
      </li>
    </ul>
   <ul>
     <li v-for="item,index in arr " :key="index">{{item.age}}</li>
   </ul>
   <div>{{sum}}</div>
   <button @click="sumFn">数组中学生年龄的和</button>
  </div>
</template>

<script>
export default {
//用任意方式, 求数组里每个学生的年龄和, 显示到页面上
data(){
  return{
     arr : [{
    name: "小明",
    age: 18
}, {
    name: "小花",
    age: 25
}, {
    name: "小爱",
    age: 21
}],
sum:''
  }
},
methods: 
  
 {
  

  sumFn(){
      
     let a= this.arr.reduce((sum, item) => sum + item.age, 0)
     this.sum=a
 
}
}
}
</script>

<style>

</style>